package com.etoak.controller;


import com.etoak.bean.*;
import com.etoak.service.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService service;

    @PostMapping("/addOrder")
    public ResultVo addOrder(@RequestBody HomestayOrder order){
        int i = service.addOrder(order);
        if(i>0){
            return  ResultVo.success("预定成功").setData(order.getOnum().toString());
        }else if(i==-1) {
            return ResultVo.error("预定房间数量不足！");
        }
        return ResultVo.error("预定失败");
    }

    @GetMapping("/selectByUid")
    public ResultVo selectByUid(Page page,String uid){
        return ResultVo.success().setData(service.selectByUid(page,uid));
    }
    @GetMapping("/selectByOnum")
    public ResultVo selectByOnum(String onum){
        return ResultVo.success().setData(service.selectByOnum(onum));
    }

    @PutMapping("/cancelOrder")
    public ResultVo cancelOrder(String onum){
        return ResultVo.success().setData(service.updateStatus(onum,3));
    }

    @DeleteMapping
    public ResultVo del(String onum){
        return ResultVo.success().setData(service.del(onum));
    }

}
